--
-- Author: shunguo.chen
-- Date: 2017-11-27 17:57:28
--

local GameDB = import(".GameDB")


function GameDB:getMountConfigs()
    local confs = self:getCachedValues("mount")
    return confs
end

function GameDB:getMountConfig(mountId)
    local conf = self:getCachedValue("mount",mountId)
    return conf
end

function GameDB:getMountSpeedConfs()
    local confs = self:getCachedValues("mount_speed")
    local rets = {}
    -- 排序
    for k,conf in pairs(confs) do
        rets[tonumber(conf.ID)] = conf
    end
    return rets
end

function GameDB:getMountStarConfigs(mountID)
    local confs = self:getCachedValues("mount_star",function(v)
        return v.mountID == tostring(mountID)
    end)
    local rets = {}
    for k,conf in pairs(confs) do
        rets[tonumber(conf.currentStar)] = conf
    end
    return rets
end

function GameDB:getMountStarConfig(id)
    local conf = self:getCachedValue("mount_star", id)
    assert(conf ~= nil, "GameDB:getMountStarConfig fail id = " .. id)
    return conf
end

function GameDB:getMountStarConfByStar(tid, star)
    local conf = self:getCachedValue("mount_star", function(v)
            return tonumber(v.mountID) == tid and tonumber(v.currentStar) == star
        end)
    return conf
end

function GameDB:getMountStarAttrs(id)
    local conf = self:getMountStarConfig(id)
    local attrs = {0,0,0}
    for i=1,3 do
        local attr = {
            tonumber(conf["attribute" .. i .. "Type"]),
            tonumber(conf["attribute" .. i .. "Value"])
        }
        attrs[i] = attr
    end
    return attrs
end

function GameDB:getMountResConfig(mountId)
    local conf = self:getCachedValue("mount_res",mountId)
    return conf
end

function GameDB:getMountSoulConf(id)
    local conf = self:getCachedValue("mount_soul",id)
    return conf
end

return GameDB